package cn.com.qingz.core.utils;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 七牛云存储存储器
 */
public class QiNiuTool {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    protected Config config;

    protected Auth auth;

    protected UploadManager uploadManager;

    protected BucketManager bucketManager;

    public QiNiuTool() {
    }

    public String uploadToken() {
        return auth.uploadToken(config.bucket, null, config.expires , null);
    }

    public Config getConfig() {
        return config;
    }

    public void setConfig(Config config) {
        this.config = config;
        if (config != null) {
            this.auth = Auth.create(config.accessKey, config.secretKey);
            bucketManager = new BucketManager(auth);
            uploadManager = new UploadManager();
        }
    }

    public static class Config {

        private String accessKey;

        private String secretKey;

        private String bucket;

        private String host;

        private int expires = 3600;

        public String getAccessKey() {
            return accessKey;
        }

        public void setAccessKey(String accessKey) {
            this.accessKey = accessKey;
        }

        public String getBucket() {
            return bucket;
        }

        public void setBucket(String bucket) {
            this.bucket = bucket;
        }

        public String getSecretKey() {
            return secretKey;
        }

        public void setSecretKey(String secretKey) {
            this.secretKey = secretKey;
        }

        public int getExpires() {
            return expires;
        }

        public void setExpires(int expires) {
            this.expires = expires;
        }

        public String getHost() {
            return host;
        }

        public void setHost(String host) {
            this.host = host;
        }
    }

    public static class Result {

        private String hash;

        private String key;

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getHash() {
            return hash;
        }

        public void setHash(String hash) {
            this.hash = hash;
        }
    }

    /*
     * 上传策略（PutPolicy）

    public static class PutPolicy {

        private String scope;

        private Integer deadline;

        public String getScope() {
            return scope;
        }

        public void setScope(String scope) {
            this.scope = scope;
        }

        public Integer getDeadline() {
            return deadline;
        }

        public void setDeadline(Integer deadline) {
            this.deadline = deadline;
        }
    }
    */
}
